<template>
  <el-dialog
    title="是否同意修改地址?"
    width="30%"
    top="10vh"
    center
    :visible.sync="visible"
    @close="visible = !visible"
  >
    <el-form ref="elForm" :model="formData" :rules="rules">
      <el-form-item prop="remark">
        <el-input
          v-model.trim="formData.remark"
          type="textarea"
          placeholder="请输入备注"
          :autosize="{ minRows: 6, maxRows: 8 }"
        />
      </el-form-item>
      <el-form-item label-width="0" class="mt-20 text-center">
        <el-button @click="submitForm(false)"> 拒绝 </el-button>
        <el-button type="primary" @click="submitForm(true)"> 同意 </el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
export default {
  name: 'OrderAddressPopup',
  props: {
    addressVisible: {
      type: Boolean,
      default: false
    },
    id: {
      type: [Number, String],
      default: 0
    }
  },
  data() {
    return {
      rules: {},
      formData: {
        remark: ''
      }
    }
  },
  computed: {
    visible: {
      get() {
        return this.addressVisible
      },
      set(val) {
        this.$emit('update:addressVisible', val)
      }
    }
  },
  methods: {
    async cacleOrder(boo) {
      const { status, msg } = await this.$http.order.orderApi.auditUpdateAddressApply({
        ...this.formData,
        id: this.id,
        status: boo
      })
      if (status === 200) {
        this.$message.success('操作成功！')
        this.$emit('update')
        this.visible = false
      } else {
        this.$message.error(msg)
      }
    },
    submitForm(boo) {
      this.$refs['elForm'].validate(async valid => {
        if (!valid) return
        this.cacleOrder(boo)
      })
    }
  }
}
</script>
